/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : OSPI_flash_hal.h
  * @brief          : Header for OSPI_flash_hal.c file.
  *                   This file contains the common defines of the application.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __OSPI_FLASH_HAL_H
#define __OSPI_FLASH_HAL_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32h7xx_hal.h"
#include "stm32h7xx_hal_ospi.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
#define OSPI_OK            ((uint8_t)0x00)
#define OSPI_ERROR         ((uint8_t)0x01)

#define QSPI_PAGE_SIZE                       256	   /* 65536 pages of 256 bytes */
#define QSPI_SECTOR_SIZE                     0x1000        // 4k
/* USER CODE END ET */

/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */

/* USER CODE END EC */

/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
#define		CMD_WRITE_ENABLE				0x06
#define		CMD_READ_STATUSREG				0x05
#define		CMD_READ_CFG_REG		        0x15
#define		CMD_WRITE_STATUSREG				0x01
#define		CMD_WRITE_STATUSREG_2			0x31
#define		CMD_READ_ID						0x9F
#define		CMD_SECTOR_ERASE				0x20
#define     CMD_FAST_READDATA               0x6B
#define		CMD_FAST_READDATA_4IO			0xEB
#define		CMD_PAGE_PROGRAM				0x32 //0x33 //0x38
#define		CMD_MEM_MAP						0xEB


uint8_t OSPI_SendCmd(uint32_t cmd, uint32_t cmdMode, uint32_t cmdSize, 
					uint32_t addr, uint32_t addrMode, uint32_t addrSize, 
					uint32_t dataMode, uint32_t dataSize, uint32_t dummy);
uint8_t OSPI_Receive(uint8_t* buf,uint32_t len);
uint8_t OSPI_Transmit(uint8_t* buf,uint32_t len);
uint8_t OSPI_SetQE(void);
uint32_t OSPI_ReadId(void);
void 	OSPI_WaitIdle(void);
uint8_t OSPI_EraseSector(uint32_t StartAddress);
void 	OSPI_Read(uint32_t Address, uint32_t Size, uint8_t * Buffer);
uint8_t OSPI_Write_Page(uint32_t Address, uint32_t Size, uint8_t * Buffer);
uint8_t OSPI_MemoryMapped(void);
uint8_t OSPI_AutoPollingMemReady(uint32_t Timeout);


/* USER CODE END EM */

/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);

/* USER CODE BEGIN EFP */

/* USER CODE END EFP */

/* Private defines -----------------------------------------------------------*/
/* USER CODE BEGIN Private defines */

/* USER CODE END Private defines */

#ifdef __cplusplus
}
#endif

#endif /* __OSPI_FLASH_HAL_H */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
